//
//  AskHeaderView.m
//  心水宝典
//
//  Created by zr on 2018/8/29.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "AskHeaderView.h"

@interface AskHeaderView ()

@property (nonatomic, strong)UIButton * topButton;
@property (nonatomic, strong)UIButton * oneButton;
@property (nonatomic, strong)UIButton * twoButton;
@property (nonatomic, strong)UIButton * threeButton;
@property (nonatomic, strong)UIButton * fourButton;
@property (nonatomic, weak)UIView * middleView;
@property (nonatomic, weak)UIButton * myPushButton;
@property (nonatomic, weak)UIImageView * labelImageView;
@property (nonatomic, weak)UIImageView * penImageView;
@property (nonatomic, weak)UIView * bottomView;

@end

@implementation AskHeaderView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    return self;
}


- (void)setupUI{
    
    self.userInteractionEnabled = YES;
    self.backgroundColor = [UIColor lightGrayColor];
    
    self.topButton = [self setupButtonWithImage:@"图层 1"];
    [self addSubview:self.topButton];
    self.oneButton = [self setupButtonWithImage:@"tu1"];
    [self addSubview:self.oneButton];
    self.twoButton = [self setupButtonWithImage:@"ceceyingyuan"];
    [self addSubview:self.twoButton];
    self.threeButton = [self setupButtonWithImage:@"haoyouhebazi"];
    [self addSubview:self.threeButton];
    self.fourButton = [self setupButtonWithImage:@"xiaoremolai"];
    [self addSubview:self.fourButton];
    
    UIView * middleView = [UIView new];
    
    middleView.backgroundColor = WHITE_COLOR;
    middleView.userInteractionEnabled = YES;
    
    self.middleView = middleView;
    
    [self addSubview:self.middleView];
    
    
    UIButton * pushButton = [UIButton new];
    
    [pushButton setTitle:@"  我的发布" forState:UIControlStateNormal];
    [pushButton setImage:ImageNamed(@"wdfb") forState:UIControlStateNormal];
    [pushButton setTitleColor:BLACK_COLOR forState:UIControlStateNormal];
    pushButton.titleLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    [pushButton addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
    
    self.myPushButton = pushButton;
    
    [self.middleView addSubview:self.myPushButton];
    
    
    UIImageView * penImageView = [UIImageView new];
    
    penImageView.image = ImageNamed(@"maobi");
    
    self.penImageView = penImageView;
    
    [self.middleView addSubview:self.penImageView];
    
    
    UIImageView * labelImageView = [UIImageView new];
    
    labelImageView.image = ImageNamed(@"fatiewendashen");
    
    self.labelImageView = labelImageView;
    
    [self.middleView addSubview:self.labelImageView];
    
    
    UIView * bottomView = [UIView new];
    
    bottomView.backgroundColor = ColorWithRGB(0xe6e6e6);//ColorWithRGB(0xF2F3F5);
    
    self.bottomView = bottomView;
    
    [self addSubview:self.bottomView];
}


-(void)layoutSubviews{
    
    [self.topButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.top.mas_equalTo(self);
        make.height.mas_equalTo(170 * SCREENH6);
    }];
    
    [self.oneButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self);
        make.top.mas_equalTo(self.topButton.mas_bottom).offset(5 * SCREENH6);
        make.width.mas_equalTo(187 * SCREENH6);
        make.height.mas_equalTo(88 * SCREENH6);
    }];
    
    [self.twoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.oneButton.mas_trailing).offset(1 * SCREENH6);
        make.top.bottom.width.mas_equalTo(self.oneButton);
    }];
    
    [self.threeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.leading.mas_equalTo(self.oneButton);
        make.top.mas_equalTo(self.oneButton.mas_bottom).offset(1 * SCREENH6);
    }];
    
    [self.fourButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.threeButton.mas_trailing).offset(1 * SCREENH6);
        make.top.bottom.width.mas_equalTo(self.threeButton);
    }];
    
    [self.middleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self);
        make.top.mas_equalTo(self.threeButton.mas_bottom).offset(10 * SCREENH6);
        make.height.mas_equalTo(34 * SCREENH6);
    }];
    
    [self.myPushButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.middleView).offset(15 * SCREENH6);
        make.centerY.mas_equalTo(self.middleView);
    }];
    
    [self.labelImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.middleView);
        make.centerX.mas_equalTo(self.middleView);
    }];
    
    [self.penImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.middleView).offset(5 * SCREENH6);
        make.leading.mas_equalTo(self.labelImageView.mas_trailing).offset(-13 * SCREENH6);
    }];
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self);
        make.height.mas_equalTo(10 * SCREENH6);
        make.bottom.mas_equalTo(self);
    }];
}

- (UIButton *)setupButtonWithImage:(NSString *)image{
    
    UIButton * button = [UIButton new];
    
    [button setImage:ImageNamed(image) forState:UIControlStateNormal];
    [button addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
    
    return button;
}


- (void)clickButton:(UIButton *)button{
 
    if (button == self.topButton) {
        
    }else{
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"changeTabbar" object:nil];
    }
}


@end
